import 'package:flutter/material.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/common/langs/text_key.dart';
import 'package:oramemo/common/styles/colors.dart';
import 'package:oramemo/entity/folder_query_entity.dart';
import 'package:oramemo/pages/transcription/files/controllers/transcriptio_files_logic.dart';
import 'package:oramemo/pages/user/management/controllers/user_management_logic.dart';
import '../../transcription_router.dart';
import 'file_action_buttons.dart';

class FileListItem extends StatelessWidget {
  final FolderQueryData data;
  const FileListItem({
    super.key,
    required this.data,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 3),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: Text(
              data.folderName ?? TextKey.unnamedFolder.tr,
              style: const TextStyle(
                fontSize: 14,
                color: Colours.text,
              ),
            ),
          ),
          FileActionButtons(
            onEdit: () {Get.toNamed(TranscriptionRouter.transcriptionFileEdit,arguments: data);},
            onDelete: () async {
              final confirm = await Get.dialog<bool>(
                AlertDialog(
                  title: Text(TextKey.confirmDelete.tr),
                  content: Text(TextKey.deleteConfirmation.tr.replaceFirst('{folderName}', data.folderName ?? TextKey.unnamedFolder.tr)),
                  actions: [
                    TextButton(
                      onPressed: () => Get.back(result: false),
                      child: Text(TextKey.cancel.tr),
                    ),
                    TextButton(
                      onPressed: () => Get.back(result: true),
                      child: Text(TextKey.confirm.tr),
                    ),
                  ],
                ),
              );
              if (confirm == true) {
                final logic = Get.find<TranscriptionFilesLogic>();
                await logic.deleteFolder(data.id??'');
              }
            },
          ),
        ],
      ),
    );
  }
}
